namespace System.Web.Core
{
    public class RolePermissionManager
    {
        private static EntityEngine entityEngine = new EntityEngine();

        public static RolePermission GetOwnerRolePermission()
        {
            Role ownerRole = RoleManager.GetRole(Configuration.Instance.OwnerRoleName);
            if (ownerRole != null)
            {
                return entityEngine.ExecuteRequest(RequestHelper.BuildGetRolePermissionRequest(ownerRole.EntityId.Value)).Reply as RolePermission;
            }
            return null;
        }
        public static RolePermission GetRolePermission(int roleId)
        {
            return entityEngine.ExecuteRequest(RequestHelper.BuildGetRolePermissionRequest(roleId)).Reply as RolePermission;
        }
        public static EntityList GetUserPermissions(int userId)
        {
            return entityEngine.ExecuteRequest(RequestHelper.BuildGetUserPermissionsRequest(userId)).Reply as EntityList;
        }
        public static int CreateRolePermission(RolePermission rolePermission)
        {
            return entityEngine.ExecuteRequest(RequestHelper.BuildCreateRolePermissionRequest(rolePermission)).Status;
        }
        public static int UpdateRolePermission(RolePermission rolePermission)
        {
            return entityEngine.ExecuteRequest(RequestHelper.BuildUpdateRolePermissionRequest(rolePermission)).Status;
        }
        public static int DeleteRolePermission(int rolePermissionId)
        {
            return entityEngine.ExecuteRequest(RequestHelper.BuildDeleteRolePermissionRequest(rolePermissionId)).Status;
        }
    }
}